package com.tac.service.wms.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tac.common.result.Result;
import com.tac.dao.wms.TransferInformationDao;
import com.tac.pojo.wms.TransferInformation;
import com.tac.service.wms.TransferInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TransferInformationServiceImpl implements TransferInformationService {

    @Autowired
    private TransferInformationDao transferInformationDao;

    // 查询
    public Result<PageInfo<TransferInformation>> getList(Integer pageNum, Integer pageSize, String material, String batchNumber, String sourceWarehouse,
                                                         String sourceStorageArea, String sourceLocation, String targetWarehouse,
                                                         String targetStorageArea, String targetLocation, Date transferTimeStart,
                                                         Date transferTimeEnd, String executor) {
        PageHelper.startPage(pageNum, pageSize);
        List<TransferInformation> list = transferInformationDao.getList(material,batchNumber,sourceWarehouse,sourceStorageArea,sourceLocation,targetWarehouse
        ,targetStorageArea,targetLocation,transferTimeStart,transferTimeEnd,executor);
        PageInfo<TransferInformation> pageInfo = new PageInfo<>(list);
        return Result.success(pageInfo);
    }

    // 添加
    public Result save(TransferInformation transferInformation) {
        Integer count = transferInformationDao.save(transferInformation);
        if (count > 0) {
            return Result.success(null);
        } else {
            return Result.error("添加失败");
        }
    }

    // 删除
    public Result remove(List<Integer> ids) {
        Integer count = transferInformationDao.remove(ids);
        if (count > 0) {
            return Result.success(null);
        } else {
            return Result.error("删除失败");
        }
    }

    // 更新
    public Result update(TransferInformation transferInformation) {
        Integer count = transferInformationDao.update(transferInformation);
        if (count > 0) {
            return Result.success(null);
        } else {
            return Result.error("更新失败");
        }
    }
}
